import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

const loginRouterName = "login"

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: loginRouterName,
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/:catchAll(.*)',
    component: () => import('@/views/error/404.vue')
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

router.beforeEach((to, from, next) => {
  if (
    // 避免无限循环
    to.name !== loginRouterName &&
    // 检查用户是否已经登录
    false
  ) {

  }
  console.log(from.fullPath)
  console.log(to.fullPath)
  next()
})

export default router